<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
${include("../common/_common.html#head",["title":"系统菜单管理"])}
<script type="text/javascript" src="${path}/admin/js/iframe.js"></script>
<script type="text/javascript" src="${path}/js/jquery-html5Validate.js"></script>
<script type="text/javascript" src="${path}/js/checkbox/jquery-hcheckbox.js"></script>
<script type="text/javascript" src="${path}/js/zTree/jquery.ztree.3.5.min.js"></script>
<link type="text/css" rel="stylesheet"  href="${path}/js/checkbox/css.css"></link>
<link type="text/css" rel="stylesheet" href="${path}/js/zTree/zTreeStyle.css"/>
<style type="text/css">
	.menu_sub{
		display: none;
	}
</style>
</head>
<body class="right_body">
	<div class="body">
		<div class="top_subnav">J4CMS内容管理平台 ＞ 栏目管理</div>
		<div class="title_h2">
			搜索
		</div>
		<p class="line" style="margin-top:0;">
		</p>
		<form action="search" method="post" enctype="application/x-www-form-urlencoded">
		<div class="filed fl">
			<label>关键词：</label>
			<input type="text" class="text" size="20" name="search" value="${search}"/>
		</div>
		<div class="filed fl">
			<button class="button" type="submit"></button>
		</div>
		</form>
        <div class="tablelist">
		<table class="table">
			<tr>
			<th colspan="9" class="top_th">
			<a href="javascript:;" class="add" id="add"><em>添加</em><span></span></a>
			<a href="javascript:;" class="edit" id="edit"><em>编辑</em><span></span></a>
			</th>
			</tr>
			<tr class="title">
			<th style="width:30px;"><input id="chkAll" name="ids" type="checkbox"/><label></label></th>
			<th style="width:30px;">排序</th>
			<th style="width:150px;text-align:left;">菜单名称</th>
			<th>菜单备注</th><th>创建时间</th><th>操作</th>
			</tr>
			#if(list)
			#for(TreeData obj : list)
				<tr>
					<td><input name="id" type="checkbox" value="${obj.id}"/><label></label></td>
					<td>${obj.attributes.cate_order}</td><td class="tdleft">${obj.text}</td><td>${obj.attributes.remark}</td><td>${obj.attributes.create_time}</td>
					<td><a href="javascript:;" class="sub" data-input="${obj.id}">展开</a>|<a href="javascript:;" class="isStop" data-input="${obj.id}">${obj.attributes.status!=0?"启用":"停用"}</a>|<a  href="javascript:;" class="delete" data-input="${obj.id}">删除</a></td>
				</tr>
				#for(TreeData obj2:obj.children)
				<tr class="menu_sub sub_${obj2.pid}">
					<td><input name="id" type="checkbox" value="${obj2.id}"/><label></label></td>
					<td>${obj2.attributes.cate_order}</td><td  class="tdleft"><span style="width:30px;display:inline-block;"></span><img src="${path}/admin/images/join.gif" style="vertical-align: middle;" />${obj2.text}</td>
					<td>${obj2.attributes.remark}</td>
					<td>${obj2.attributes.create_time}</td>
					<td><a href="javascript:;" class="sub" data-input="${obj2.id}">展开</a>|<a href="javascript:;" class="isStop" data-input="${obj2.id}">${obj2.attributes.status!=0?"启用":"停用"}</a>|<a  href="javascript:;" class="delete" data-input="${obj2.id}">删除</a></td>
				</tr>
				#end
			#end
			#else
				<tr><td colspan="7">没有数据</td></tr>
			#end
		</table>
        </div>
	</div>
<script type="text/javascript">
function addObj(){
	api = $.dialog({id:'msgDialogAdd',title: '添加栏目',ok:function(){
		$("#addform").submit();
		return false;
	},cancel:function(){
		return true;
	}});
	$.ajax({
		url:'add.html',
		success:function(data){
			api.content(data);
		},
		cache:false
	});
}
function editObj(){
	var chk = $("input[name='id']:checked")[0];
	if(chk){
		api = $.dialog({id:'msgDialogUpdate',title: '编辑栏目',ok:function(){
			$("#addform").submit();
			return false;
		},cancel:function(){
			return true;
		}});
		$.ajax({
			url:'edit/'+$(chk).val(),
			success:function(data){
				api.content(data);
			},
			cache:false
		});
	}else{
		$.dialog({title:'提示',content:'请选择一个栏目.'}).time(2);
	}
}
function reloadMe(t){
	if(isNaN(t)){
		try {
			document.forms[0].submit();
		} catch (e) {
		}
	}
	else{
		setTimeout(function(){
			document.forms[0].submit();
		},t);
	}
}
$(function(){
	$("#add").click(function(e){
		e.preventDefault();
		addObj();
	});
	$("#edit").click(function(e){
		e.preventDefault();
		editObj();
	});
	$(".delete").click(function(e){
		e.stopPropagation();
		var id = $(this).attr('data-input');
		$.dialog.confirm("您确定要删除该条数据吗??",function(){
			$.ajax({
				url:'delete/'+id,
				dataType:'text',
				success:function(d){
					if(d=='true'){
						$.dialog({title:'提示',content:'操作成功!'}).time(1);
					}else{
						$.dialog({title:'提示',content:d}).time(3);
					}
					reloadMe(2000);
				},
				error:function(){
					$.dialog({title:'提示',content:'操作失败'}).time(1);
					reloadMe(1000);
				}
			});
		});
	});
	$(".isStop").click(function(e){
		e.stopPropagation();
		var id = $(this).attr('data-input');
		var url = '';
		if($(this).text()=='停用'){
			url = 'disable/'+id;
		}else{
			url = 'enable/'+id;
		}
		$.dialog.confirm("您确定要操作该条数据吗??",function(){
			$.ajax({
				url:url,
				dataType:'text',
				success:function(d){
					if(d=='true'){
						$.dialog({title:'提示',content:'操作成功!'}).time(1);
					}else{
						$.dialog({title:'提示',content:d}).time(3);
					}
					reloadMe(2000);
				},
				error:function(){
					$.dialog({title:'提示',content:'操作失败'}).time(1);
					reloadMe(1000);
				}
			});
		});
		
	});
	$(".sub").click(function(e){
		e.stopPropagation();
		var id = $(this).attr('data-input');
		if($(this).text()=='展开'){
			$(".sub_"+id).removeClass('menu_sub');
			$(this).text('合并');
		}else{
			$(".sub_"+id).addClass('menu_sub');
			$(this).text('展开');
		}
		return;
		
		$.ajax({
			url:'sub/'+id,
			dataType:'json',
			success:function(d){
				if(d.success){
					if(d.data.length>0){
						
					}else{
						//没有子目录
					}
				}else{
					//错误
				}
			}
		});
		
		
	});
	$("#chkAll").change(function(e){
		e.stopPropagation();
		if($(this).attr("checked")){
			$("input[name='id']").attr("checked",true);
		}else{
			$("input[name='id']").attr("checked",false);
		}
		$("input[name='id']").change();
	});
	$("input[name='id']").click(function(e){
		e.stopPropagation();
	});
	$(".table").hcheckbox();
	
	$(".sub").click();
});
</script>
</body>
</html>
